package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.BaseMemberDao;
import com.mstore.pojo.BaseMember;

public class BaseMemberService {

	private BaseMemberDao baseMemberDao;

	public void save(BaseMember baseMember) {
		baseMemberDao.save(baseMember);
	}

	public void delete(BaseMember baseMember) {
		baseMemberDao.delete(baseMember);
	}

	/**
	 * 更新
	 */
	public void updateBaseMember(BaseMember baseMember) {
		baseMemberDao.updateBaseMember(baseMember);
	}

	/**
	 * 根据memberId和eaId更新
	 */
	public void updateBaseMember1(BaseMember baseMember) {
		baseMemberDao.updateBaseMember1(baseMember);
	}

	/**
	 * 根据memberId查询记录
	 */
	public List<BaseMember> getBaseMembersByMemberId(Long memberId) {
		List<BaseMember> baseMembers = new ArrayList<BaseMember>();
		List<Object> objects = baseMemberDao.getBaseMembersByMemberId(memberId);
		for (Object object : objects) {
			baseMembers.add((BaseMember) object);
		}
		return baseMembers;
	}

	/**
	 * 根据eaId查询记录
	 */
	public List<BaseMember> getBaseMembersByEaId(Long eaId) {
		List<BaseMember> baseMembers = new ArrayList<BaseMember>();
		List<Object> objects = baseMemberDao.getBaseMembersByEaId(eaId);
		for (Object object : objects) {
			baseMembers.add((BaseMember) object);
		}
		return baseMembers;
	}

	/**
	 * 根据eaId查询记录 分页
	 */
	public List<BaseMember> getBaseMembersByEaId(Long eaId, int index) {
		List<BaseMember> baseMembers = new ArrayList<BaseMember>();
		List<Object> objects = baseMemberDao.getBaseMembersByEaId(eaId, index);
		for (Object object : objects) {
			baseMembers.add((BaseMember) object);
		}
		return baseMembers;
	}

	/**
	 * 查询企业会员总数
	 */
	public int countBaseMemberByEaId(Long eaId) {
		return baseMemberDao.countBaseMemberByEaId(eaId);
	}

	/**
	 * 根据memberId和eaId查询记录
	 */
	public BaseMember getOneBaseMemberByMemberIdAndEaId(Long memberId, Long eaId) {
		Object object = baseMemberDao.getOneBaseMemberByMemberIdAndEaId(
				memberId, eaId);
		return object != null ? (BaseMember) object : null;
	}

	/**
	 * 根据memberId和eaId更新余额
	 */
	public void updateBaseMemberBanlance(BaseMember baseMember) {
		baseMemberDao.updateBaseMemberBanlance(baseMember);
	}
	
	/**
	 * 查询某时间段内企业会员的数量
	 */
	public Long getCountBaseMemberByTime(Long eaId, String begin, String end) {
		return baseMemberDao.getCountBaseMemberByTime(eaId, begin, end);
	}
	
	/**
	 * 通过baseMemberId查询
	 */
	public BaseMember getOneBaseMemberByBaseMemberId(Long baseMemberId) {
		Object object = baseMemberDao.getOneBaseMemberByBaseMemberId(baseMemberId);
		return object != null ? (BaseMember) object : null;
	}

	public BaseMemberDao getBaseMemberDao() {
		return baseMemberDao;
	}

	public void setBaseMemberDao(BaseMemberDao baseMemberDao) {
		this.baseMemberDao = baseMemberDao;
	}
	
}
